package com.xintonghua.bussiness;

import android.app.Application;
import android.content.Context;

import com.alibaba.sdk.android.oss.ClientConfiguration;
import com.alibaba.sdk.android.oss.OSS;
import com.alibaba.sdk.android.oss.OSSClient;
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
import com.avos.avoscloud.AVOSCloud;
import com.litesuits.orm.LiteOrm;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import org.xutils.x;


/**
 * 作者：wanxianyi
 * 时间：2018/3/7.
 * 包名：com.xintonghua.bussiness
 */

public class MyAppLication extends Application {
    private static MyAppLication context;
    private static OSS oss;
    public static LiteOrm sDb;
    private static final String DB_NAME = "search.db";
    @Override
    public void onCreate() {
        super.onCreate();
        if (context == null) {
            context = this;
        }
        // 初始化参数依次为 this, AppId, AppKey
        AVOSCloud.initialize(this, "M4tjhGHWXpYaWqNsLIcmzSqy-MdYXbMMI", "Xlq9xKU0LNgYBPuVaOyVofGj");

        UMShareAPI.get(this);
        PlatformConfig.setWeixin("wxaef20a1fd159db53", "91bab6c4376c14af4fcf13e85802fc9b");
        PlatformConfig.setQQZone("1106900178", "Z6AfhHLFW5A3PHaK");
        sDb = LiteOrm.newSingleInstance(this, DB_NAME);
        x.Ext.init(this);//xUtils初始化
        x.Ext.setDebug(false);// 是否输出debug日志*
        initOss();
    }
    /**
     * 初始化阿里云
     */
    private void initOss() {
        String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
        OSSCredentialProvider credentialProvider = new OSSPlainTextAKSKCredentialProvider("LTAIAE4SXt8GWQzn", "hlheKDFvM6Z6P2AuKYsOThvJ5rsrr8");
        ClientConfiguration conf = new ClientConfiguration();
        conf.setConnectionTimeout(15 * 1000); // 连接超时，默认15秒
        conf.setSocketTimeout(15 * 1000); // socket超时，默认15秒
        conf.setMaxConcurrentRequest(5); // 最大并发请求书，默认5个
        conf.setMaxErrorRetry(2); // 失败后最大重试次数，默认2次
        oss = new OSSClient(getApplicationContext(), endpoint, credentialProvider, conf);
    }
    public static OSS getOss() {
        return oss;
    }

    public static Context getContext() {
        return context;
    }

    public static MyAppLication getInstance() {
        return context;
    }

}
